package com.esri.core.portal;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.achartengine.internal.a;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class BaseMap {
    String a;
    final ArrayList<WebMapLayer> b = new ArrayList<>();

    protected BaseMap() {
    }

    public String getTitle() {
        return this.a;
    }

    public List<WebMapLayer> getBaseMapLayers() {
        return this.b;
    }

    public static BaseMap fromJson(JsonParser jsonParser) throws PortalException {
        ArrayList<WebMapLayer> arrayList;
        try {
            BaseMap baseMap = new BaseMap();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if (a.b.equals(currentName)) {
                    baseMap.a = jsonParser.getText();
                } else if ("baseMapLayers".equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            WebMapLayer fromJson = WebMapLayer.fromJson(jsonParser);
                            fromJson.mIsBaseLayer = true;
                            baseMap.b.add(fromJson);
                        }
                    } else {
                        jsonParser.skipChildren();
                    }
                } else {
                    jsonParser.skipChildren();
                }
            }
            String str = baseMap.a;
            if (str != null && str.trim().length() != 0 && (arrayList = baseMap.b) != null && arrayList.size() > 0) {
                Iterator<WebMapLayer> it = baseMap.b.iterator();
                while (it.hasNext()) {
                    WebMapLayer next = it.next();
                    if (next.e != null && next.e.trim().length() == 0) {
                        next.e = baseMap.a;
                    }
                }
            }
            return baseMap;
        } catch (Exception e) {
            throw new PortalException("Unable to construct a BaseMap", e);
        }
    }
}
